/**
 * jar包信息管理初始化
 */
var Jaruse = {
    id: "JaruseTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Jaruse.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '渠道', field: 'channel', visible: true, align: 'center', valign: 'middle'},
            {title: 'jar包名称', field: 'jarName', visible: true, align: 'center', valign: 'middle'},
            {title: '是否能用', field: 'isUse', visible: true, align: 'center', valign: 'middle'},
            {title: 'jar包版本', field: 'jarVersion', visible: true, align: 'center', valign: 'middle'},
            {title: '国家', field: 'country', visible: true, align: 'center', valign: 'middle'},
            {title: '省份', field: 'province', visible: true, align: 'center', valign: 'middle'},
            {title: '机型', field: 'model', visible: true, align: 'center', valign: 'middle'},
            {title: '运营商', field: 'opeartor', visible: true, align: 'center', valign: 'middle'},
            {title: '系统版本', field: 'os', visible: true, align: 'center', valign: 'middle'},
            {title: '请求IP', field: 'reqip', visible: true, align: 'center', valign: 'middle'},
            {title: '手机唯一标识', field: 'udid', visible: true, align: 'center', valign: 'middle'},
            {title: 'imsi', field: 'imsi', visible: true, align: 'center', valign: 'middle'},
            {title: 'imei', field: 'imei', visible: true, align: 'center', valign: 'middle'},
            {title: 'mac地址', field: 'mac', visible: true, align: 'center', valign: 'middle'},
            {title: '时间', field: 'date', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Jaruse.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Jaruse.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加jar包信息
 */
Jaruse.openAddJaruse = function () {
    var index = layer.open({
        type: 2,
        title: '添加jar包信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/jaruse/jaruse_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看jar包信息详情
 */
Jaruse.openJaruseDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'jar包信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/jaruse/jaruse_update/' + Jaruse.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除jar包信息
 */
Jaruse.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/jaruse/delete", function (data) {
            Feng.success("删除成功!");
            Jaruse.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("jaruseId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询jar包信息列表
 */
Jaruse.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Jaruse.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Jaruse.initColumn();
    var table = new BSTable(Jaruse.id, "/jaruse/list", defaultColunms);
    table.setPaginationType("client");
    Jaruse.table = table.init();
});
